//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "CovarianceAttributes.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  CovarianceAttributes* covarianceAttributes = NULL;
  
  if (argc < 4) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./ComputePatternsCovariance <Arff File>";
    cout <<                            " <Filename Out with Patterns List>";
    cout <<                            " <Filename Out with covariance matrix>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    covarianceAttributes = new CovarianceAttributes ();
    
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << "                           Arff File : " << argv[1] << endl;
    cout << "     Filename Out with Patterns List : " << argv[2] << endl;
    cout << " Filename Out with covariance matrix : " << argv[3] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
    cout << "Preparing Files..." << endl;
    covarianceAttributes->Attributes()->Filename()->In(argv[1]);
    covarianceAttributes->FilenameAttributes()->In(argv[2]);
    covarianceAttributes->FilenameMatrix()->In(argv[3]);
    
  }
  
  cout << "Loading the Arff file..." << endl;
  if (!covarianceAttributes->Attributes()->LoadData())
    cout << "Error loading the Arff file..." << endl;
  
  cout << "Computing the covariance..." << endl;
  if (!covarianceAttributes->ComputeCovariance())
    cout << "Error computing the covariance..." << endl;
  
  cout << "Writing results..." << endl;
  if (!covarianceAttributes->WriteResultMatrix())
    cout << "Error writing results..." << endl;
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (covarianceAttributes) delete covarianceAttributes;
  
  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

